home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / PartMaker 4.3 / FindEverything.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-12  |  2.6 KB  |  99 lines  |  [TEXT/MPS ]

  1. /*****************************************************************************/
  2.  
  3. /* A utility routine called by NameFileSearch and CreatorTypeFileSearch to
  4. ** allocate a optimization buffer. */
  5.  
  6. static    Ptr    GetSearchBuffer(long *buffSize);
  7. static    Ptr    GetSearchBuffer(long *buffSize)
  8. {
  9.     Ptr    tempPtr;
  10.     
  11.     *buffSize = 0x00004000;        /* start by trying for a 16K buffer */
  12.     while ( *buffSize != 0 )    /* and keep trying until *buffSize is zero */
  13.     {
  14.         tempPtr = NewPtr(*buffSize);
  15.         if ( tempPtr != NULL )
  16.             break;    /* got it */
  17.         else
  18.             *buffSize -= 0x00000400;    /* didn't get it, subtract 1K and try again */
  19.     }
  20.     return ( tempPtr );
  21. }
  22.  
  23. /*****************************************************************************/
  24.  
  25. pascal OSErr IndexedSearch(CSParamPtr pb, long dirID);
  26.  
  27. pascal    OSErr    FindEverything(short vRefNum,
  28.                                long dirID,
  29.                                FSSpecPtr matches,
  30.                                long reqMatchCount,
  31.                                long *actMatchCount,
  32.                                Boolean newSearch);
  33. pascal    OSErr    FindEverything(short vRefNum,
  34.                                long dirID,
  35.                                FSSpecPtr matches,
  36.                                long reqMatchCount,
  37.                                long *actMatchCount,
  38.                                Boolean newSearch)
  39. {
  40.     CInfoPBRec        searchInfo1, searchInfo2;
  41.     HParamBlockRec    pb;
  42.     OSErr            error;
  43.     static CatPositionRec catPosition;
  44.     
  45.     pb.csParam.ioNamePtr = NULL;
  46.     pb.csParam.ioVRefNum = vRefNum;
  47.     pb.csParam.ioMatchPtr = matches;
  48.     pb.csParam.ioReqMatchCount = reqMatchCount;
  49.     pb.csParam.ioSearchBits = 0;        /* find all matches */
  50.     pb.csParam.ioSearchInfo1 = &searchInfo1;
  51.     pb.csParam.ioSearchInfo2 = &searchInfo2;
  52.     pb.csParam.ioSearchTime = 0;
  53.     if ( newSearch )
  54.     {
  55.         catPosition.initialize = 0;    /* then search from beginning of catalog */
  56.     }
  57.     pb.csParam.ioCatPosition = catPosition;
  58.     pb.csParam.ioOptBuffer = GetSearchBuffer(&pb.csParam.ioOptBufSize);
  59.  
  60.     if ( dirID == fsRtDirID )
  61.     {
  62.         error = PBCatSearchSync((CSParamPtr)&pb);
  63.     }
  64.     else
  65.     {
  66.         error = IndexedSearch((CSParamPtr)&pb, dirID);
  67.     }
  68.  
  69.     if ( (error == noErr) ||                            /* If no errors or the end of catalog was */
  70.          (error == eofErr) )                            /* found, then the call was successful so */
  71.     {
  72.         *actMatchCount = pb.csParam.ioActMatchCount;    /* return the match count */
  73.     }
  74.     else
  75.     {
  76.         *actMatchCount = 0;                            /* else no matches found */
  77.     }
  78.     
  79.     if ( (error == noErr) ||                        /* If no errors */
  80.          (error == catChangedErr) )                    /* or there was a change in the catalog */
  81.     {
  82.         catPosition = pb.csParam.ioCatPosition;
  83.             /* we can probably start the next search where we stopped this time */
  84.     }
  85.     else
  86.     {
  87.         catPosition.initialize = 0;
  88.             /* start the next search from beginning of catalog */
  89.     }
  90.     
  91.     if ( pb.csParam.ioOptBuffer != NULL )
  92.     {
  93.         DisposPtr(pb.csParam.ioOptBuffer);
  94.     }
  95.         
  96.     return ( error );
  97. }
  98.  
  99.